const gulp = require("gulp");
const cssmin = require("gulp-cssmin");
const autoprefixer = require("gulp-autoprefixer");
const uglify = require("gulp-uglify");
const babel = require("gulp-babel");
const htmlmin = require("gulp-htmlmin");

function cssFn(){
    return gulp.src("./src/css/*.css")
        .pipe(autoprefixer("last 2 version","safari 5","ie 8","ie 9","opera 12.1","ios 6","android 4"))
        .pipe(cssmin())
        .pipe(gulp.dest("./project/css"))
}

module.exports.css = cssFn;

function jsFn(){
    return gulp.src("./src/js/**")
    .pipe(babel({
        presets:["@babel/env"]
    }))
    .pipe(uglify())
    .pipe(gulp.dest("./project/js"))
}
module.exports.js = jsFn;

function htmlFn(){
    return gulp.src("./src/pages/**")
        .pipe(htmlmin({
            removeEmptyAttributes:true,
            collapseWhitespace:true
        }))
        .pipe(gulp.dest("./project/pages"));
}

module.exports.html = htmlFn;

function indexFn(){
    return gulp.src("./src/index.html")
        .pipe(htmlmin({
            removeEmptyAttributes:true,
            collapseWhitespace:true
        }))
        .pipe(gulp.dest("./project"));
}
module.exports.index = indexFn;

function phpFn(){
    return gulp.src("./src/php/**")
    .pipe(gulp.dest("./project/php"))
}
module.exports.php = phpFn;

function staticFn(){
    return gulp.src("./src/static/**/*")
    .pipe(gulp.dest("./project/static"))
}
module.exports.static = staticFn;

exports.all = gulp.parallel(staticFn,phpFn,indexFn,htmlFn,jsFn,cssFn);